//
//  ZZNavViewController.m
//  Sina
//
//  Created by 张卓 on 2017/1/17.
//  Copyright © 2017年 ZZ. All rights reserved.
//

#import "ZZNavViewController.h"

@interface ZZNavViewController ()<UIGestureRecognizerDelegate>

@end

@implementation ZZNavViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    [self setupUI];
}

- (void)setupUI {
    
    self.interactivePopGestureRecognizer.delegate = self;
}

- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch {
    
    //        if childViewControllers.count == 1 {
    //            return false
    //        }else{
    //            return true
    //        }
    return self.childViewControllers.count != 1;
}


- (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated {
    
    if(self.childViewControllers.count > 0){
        NSString *title = @"返回";
        if(self.childViewControllers.count == 1){
            title = self.childViewControllers.firstObject.title;
            viewController.hidesBottomBarWhenPushed = YES;
        }
        viewController.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc]initWithCustomView:[UIButton leftBntWith:@"navigationbar_back_withtext" andTitle:title andTarget:self andAction:@selector(leftClick)]];
        
    }
    
    [super pushViewController:viewController animated:animated];
    
}
- (void)leftClick {
    [self popViewControllerAnimated:YES];
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
